// 语句块

function addArduinoCod (Blockly) {
    Blockly.Arduino.test = function (block) {
        // If/elseif/else condition.
        return '111 \n';
    };
    Blockly.Arduino.serial_band_rate = function (block) {
        return 'serial_band_rate() \n';
    }
 //模式
Blockly.Arduino['inout_pinMode1'] = function(block) {
var dropdown_PINS = this.getFieldValue('PINS');
var dropdown_MODE = this.getFieldValue('MODE');
return  'pinMode(' + dropdown_PINS + ', ' + dropdown_MODE + '); \n';
}
//数字写
Blockly.Arduino['digitalWrite'] = function(block) {
var dropdown_PINS = this.getFieldValue('PINS');
var dropdown_STATE = this.getFieldValue('STATE');
return  'digitalWrite(' + dropdown_PINS + ', ' + dropdown_STATE + '); \n';
}
//模拟写
Blockly.Arduino['analogWrite'] = function(block) {
var dropdown_analogPINS = this.getFieldValue('analogPINS');
var value_analogWrites = Blockly.Arduino.valueToCode(this, 'analogWrites', Blockly.Arduino.ORDER_ATOMIC);
return  'analogWrite(' + dropdown_analogPINS + ', ' + value_analogWrites + '); \n';
}
//数字读
Blockly.Arduino['digitalRead'] = function(block) {
var dropdown_PINS = this.getFieldValue('PINS');
var code = 'digitalRead(' + dropdown_PINS + ')';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//模拟读
Blockly.Arduino['analogRead'] = function(block) {
var dropdown_ANALOGPINS = this.getFieldValue('ANALOGPINS');
var code = 'analogRead(' + dropdown_ANALOGPINS + ')';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//定时器执行
// Blockly.Arduino['timer'] = function(block) {
//   var value_timers = Blockly.Arduino.valueToCode(this, 'timers', Blockly.Arduino.ORDER_ATOMIC);
//   Blockly.Arduino.definitions_['include_timer'] = '#include <MsTimer2.h>';
//     var branch = Blockly.Arduino.statementToCode(this, 'DO');
//     var code2 = ' void msTimer2_func() {\n' + branch + '}\n';
//     Blockly.Arduino.definitions_['func_timer'] = code2;
//     return 'MsTimer2::set('+value_timers+', msTimer2_func);\n';
// }
//定时器启动
Blockly.Arduino['timeron'] = function(block) {
  Blockly.Arduino.definitions_['include_timeron'] = '#include <MsTimer2.h>';
    return 'MsTimer2::start();\n';
}
//定时器停止
Blockly.Arduino['timeroff'] = function(block) {
  Blockly.Arduino.definitions_['include_timeroff'] = '#include <MsTimer2.h>';
    return 'MsTimer2::stop();\n';
}
//系统运行时间
Blockly.Arduino['runtime'] = function(block) {
	var dropdown_runtimes = this.getFieldValue('runtimes');
var code = ''+dropdown_runtimes+'()';
return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//管脚中断
// Blockly.Arduino['pininterrupt'] = function(block) {
//   var dropdown_INTERRUPTPINS = this.getFieldValue('INTERRUPTPINS');
//   var dropdown_INTERRUPT = this.getFieldValue('INTERRUPT');
//   Blockly.Arduino.definitions_['include_pininterrupt'] = '#include <PinChangeInt.h>';
//     var branch = Blockly.Arduino.statementToCode(this, 'DO');
//     var code2 = ' void attachPinInterrupt_fun() {\n' + branch + '}\n';
//     Blockly.Arduino.definitions_['func_pininterrupt'] = code2;
//     return 'PCintPort::attachInterrupt('+dropdown_INTERRUPTPINS+',attachPinInterrupt_fun,'+dropdown_INTERRUPT+');\n';
// }

//脉冲长度
Blockly.Arduino['pulse'] = function(block) {
var dropdown_PULSEPINS = this.getFieldValue('PULSEPINS');
var dropdown_PULSES = this.getFieldValue('PULSES');
var code = 'pulseIn('+dropdown_PULSEPINS+', '+dropdown_PULSES+')';
return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//脉冲长度超时
Blockly.Arduino['pulse2'] = function(block) {
var dropdown_PULSEPINS = this.getFieldValue('PULSEPINS');
var dropdown_PULSES = this.getFieldValue('PULSES');
var value_pulse2s = Blockly.Arduino.valueToCode(this, 'pulse2s', Blockly.Arduino.ORDER_ATOMIC);
var code = 'pulseIn('+dropdown_PULSEPINS+', '+dropdown_PULSES+','+value_pulse2s+')';
return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//串口波特率
Blockly.Arduino['serialbegin'] = function(block) {
	var dropdown_SerialS1 = this.getFieldValue('SerialS1');
var dropdown_serialbegins = this.getFieldValue('serialbegins');
//Blockly.Arduino.definitions_['setup_serialbegin'] = '';
return  ''+dropdown_SerialS1+'.begin(' + dropdown_serialbegins + '); \n';
}
//串口打印字符不换行
Blockly.Arduino['serialprintstring'] = function(block) {
	var dropdown_SerialS22 = this.getFieldValue('SerialS22');
var value_serialprints1 = Blockly.Arduino.valueToCode(this, 'serialprints1', Blockly.Arduino.ORDER_ATOMIC);
return  ''+dropdown_SerialS22+'.print(' + value_serialprints1.replace(/'/g, '"') + '); \n';
}
//串口打印字符
Blockly.Arduino['serialprint'] = function(block) {
	var dropdown_SerialS2 = this.getFieldValue('SerialS2');
var value_serialprints = Blockly.Arduino.valueToCode(this, 'serialprints', Blockly.Arduino.ORDER_ATOMIC);
return  ''+dropdown_SerialS2+'.println(' + value_serialprints.replace(/'/g, '"') + '); \n';
}
//串口打印数字不换行
Blockly.Arduino['serialprintnum1'] = function(block) {
		var dropdown_SerialS33 = this.getFieldValue('SerialS33');
var value_serialprintsss = Blockly.Arduino.valueToCode(this, 'serialprintsss', Blockly.Arduino.ORDER_ATOMIC);
return  ''+dropdown_SerialS33+'.print(' + value_serialprintsss + '); \n';
}
//串口打印数字
Blockly.Arduino['serialprintnum'] = function(block) {
		var dropdown_SerialS3 = this.getFieldValue('SerialS3');
var value_serialprintss = Blockly.Arduino.valueToCode(this, 'serialprintss', Blockly.Arduino.ORDER_ATOMIC);
return  ''+dropdown_SerialS3+'.println(' + value_serialprintss + '); \n';
}
//串口打印16进制
Blockly.Arduino['serialprint16num'] = function(block) {
	var dropdown_SerialS4 = this.getFieldValue('SerialS4');
var value_serialprint16nums = Blockly.Arduino.valueToCode(this, 'serialprint16nums', Blockly.Arduino.ORDER_ATOMIC);
return  ''+dropdown_SerialS4+'.println('+value_serialprint16nums+',HEX);\n';
}
//串口有数据可读
Blockly.Arduino['serialava'] = function(block) {
	var dropdown_SerialS = this.getFieldValue('SerialS');
var code = ''+dropdown_SerialS+'.available() > 0';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//串口读取字节
Blockly.Arduino['serialread'] = function(block) {
		var dropdown_Serials = this.getFieldValue('Serials');
 var code = ''+dropdown_Serials+'.read()';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//类型转换
Blockly.Arduino['changetype'] = function(block) {
var dropdown_types = this.getFieldValue('types');
var value_changetypes = Blockly.Arduino.valueToCode(this, 'changetypes', Blockly.Arduino.ORDER_ATOMIC);
 var code = '('+dropdown_types+')'+value_changetypes+'';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//类型转换2
Blockly.Arduino['changetypes'] = function(block) {
var value_changetypess = Blockly.Arduino.valueToCode(this, 'changetypess', Blockly.Arduino.ORDER_ATOMIC);
 var code = '(int)('+value_changetypess.replace(/'/g, '"')+')';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//软串口
Blockly.Arduino['softserial'] = function(block) {
var dropdown_TX1 = this.getFieldValue('TX1');
var dropdown_RX1 = this.getFieldValue('RX1');
Blockly.Arduino.definitions_['include_softserial'] = '#include <SoftwareSerial.h>';
Blockly.Arduino.definitions_['softserial'] = 'SoftwareSerial softser = SoftwareSerial('+dropdown_RX1+', '+dropdown_TX1+');';
var code = '';
 return code;
}
//串口中断
Blockly.Arduino['serial_event'] = function(block) {

  var serial_select = this.getFieldValue('Serials');
    var funcName = 'attachPinInterrupt_fun_' + serial_select;
    var branch = Blockly.Arduino.statementToCode(this, 'DO');
    var code2 = ' void '+serial_select+'Event() {\n' + branch + '}\n';
    Blockly.Arduino.definitions_['func_'+funcName+''] = code2;
    return "";

}
//串口清空缓存数据
Blockly.Arduino['serial_flush'] = function(block) {

  var serial_select = this.getFieldValue('Serials');
    return ''+serial_select+'.flush();\n';

}
//串口读取字符串直到
Blockly.Arduino['serial_read'] = function(block) {
	var serial_select = this.getFieldValue('Serials');
var value_serialprints2 = Blockly.Arduino.valueToCode(this, 'serialprints2', Blockly.Arduino.ORDER_ATOMIC);
 var code = ''+serial_select+'.readStringUntil('+value_serialprints2+')';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//超声波初始化
Blockly.Arduino['ultrasonicinit'] = function(block) {
var dropdown_TRIGs = this.getFieldValue('TRIGs');
var dropdown_ECHOs = this.getFieldValue('ECHOs');
Blockly.Arduino.definitions_['func_ultrasonicdistance'] = ' float checkdistance() {\n   digitalWrite('+dropdown_TRIGs+', LOW);\n   delayMicroseconds(2);\n   digitalWrite('+dropdown_TRIGs+', HIGH);\n   delayMicroseconds(10);\n   digitalWrite('+dropdown_TRIGs+', LOW);\n   float distance = pulseIn('+dropdown_ECHOs+', HIGH) / 58.00;\n   delay(10);\n   return distance;\n}';
 return 'pinMode('+dropdown_TRIGs+', OUTPUT);\npinMode('+dropdown_ECHOs+', INPUT);\n';
}
//超声波测距
Blockly.Arduino['ultrasonicdistance'] = function(block) {
var code = 'checkdistance()';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//dht初始化
Blockly.Arduino['initdht'] = function(block) {
var dropdown_PINSs = this.getFieldValue('PINSs');
Blockly.Arduino.definitions_['include_initdht'] = '#include <dht.h>';
Blockly.Arduino.definitions_['initdht'] = 'dht myDHT_'+dropdown_PINSs+';'
Blockly.Arduino.definitions_['func_initdht'] = ' int gettemperature() {\n  int chk = myDHT_'+dropdown_PINSs+'.read11('+dropdown_PINSs+');\n  int value = myDHT_'+dropdown_PINSs+'.temperature;\n  return value;}\n int gethumidity() {\n  int chk = myDHT_'+dropdown_PINSs+'.read11('+dropdown_PINSs+');\n  int value = myDHT_'+dropdown_PINSs+'.humidity;\n  return value;\n}';
 return '';
}
//dht
Blockly.Arduino['dht'] = function(block) {
//var dropdown_PINS = this.getFieldValue('PINS');
var dropdown_temhum = this.getFieldValue('temhum');

var code = 'get'+dropdown_temhum+'()';
return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//舵机初始化
Blockly.Arduino['initservo'] = function(block) {
var dropdown_servopinss = this.getFieldValue('servopinss');
Blockly.Arduino.definitions_['include_initservo'] = '#include <Servo.h>';
Blockly.Arduino.definitions_['initservo_'+dropdown_servopinss+''] = 'Servo servo_'+dropdown_servopinss+';';
  return 'servo_'+dropdown_servopinss+'.attach('+dropdown_servopinss+');\n';
}
//舵机
Blockly.Arduino['servo'] = function(block) {
var dropdown_servopins = this.getFieldValue('servopins');
var value_servoangle = Blockly.Arduino.valueToCode(this, 'servoangle', Blockly.Arduino.ORDER_ATOMIC);//
  return 'servo_'+dropdown_servopins+'.write('+value_servoangle+');\n';
}
//lcd配置地址
Blockly.Arduino['lcdinit'] = function(block) {
var value_lcdinits = Blockly.Arduino.valueToCode(this, 'lcdinits', Blockly.Arduino.ORDER_ATOMIC);
  Blockly.Arduino.definitions_['include_lcdinit'] = '#include <LiquidCrystal_I2C.h>\n#include <Wire.h>';
    Blockly.Arduino.definitions_['lcdinit'] = 'LiquidCrystal_I2C mylcd('+value_lcdinits.replace(/'/g, "")+',16,2);';
  //Blockly.Arduino.definitions_['setup_lcdinit'] = '';
return  'mylcd.init();\nmylcd.backlight();\n';
}
//lcd光标
Blockly.Arduino['lcdposition'] = function(block) {
var value_col = Blockly.Arduino.valueToCode(this, 'col', Blockly.Arduino.ORDER_ATOMIC);
var value_row = Blockly.Arduino.valueToCode(this, 'row', Blockly.Arduino.ORDER_ATOMIC);
  return  'mylcd.setCursor('+value_col+'-1, '+value_row+'-1);\n';
}
//lcd打印
Blockly.Arduino['lcdprint'] = function(block) {
var value_lcdprints = Blockly.Arduino.valueToCode(this, 'lcdprints', Blockly.Arduino.ORDER_ATOMIC);
return  'mylcd.print('+value_lcdprints.replace(/'/g, '"')+');\n';
}
//lcd清屏
Blockly.Arduino['lcdclear'] = function(block) {
return  'mylcd.clear();\n';
}
//红外发送
Blockly.Arduino['irsend'] = function(block) {
var dropdown_irpins = this.getFieldValue('irpins');
var value_irdata = Blockly.Arduino.valueToCode(this, 'irdata', Blockly.Arduino.ORDER_ATOMIC);
var value_irbyte = Blockly.Arduino.valueToCode(this, 'irbyte', Blockly.Arduino.ORDER_ATOMIC);
Blockly.Arduino.definitions_['include_irsend'] = '#include <IRremote.h>';
Blockly.Arduino.definitions_['irsend'] = 'IRremote irsend(3);';
  return  'irsend.sendNEC('+value_irdata.replace(/'/g, "")+','+value_irbyte.replace(/'/g, "")+');\n';
}
//红外接收初始化
Blockly.Arduino['initirreceive'] = function(block) {
var dropdown_irpinss = this.getFieldValue('irpinss');
Blockly.Arduino.definitions_['include_initirreceive'] = '#include <IRremote.h>';
Blockly.Arduino.definitions_['initirreceive'] = 'IRremote irrecv('+dropdown_irpinss+');\n';
  return  'irrecv.enableIRIn();\n';
}
//红外接收
Blockly.Arduino['irreceive'] = function(block) {

var code = 'irrecv.getCode()';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//红外接收的值
Blockly.Arduino['irgetdate'] = function(block) {
 var code = 'irrecv.getCode()';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//红外接收下一个值
Blockly.Arduino['irgetnextdate'] = function(block) {
  return  'irrecv.resume();\n';
}
//tm1637数码管初始化
Blockly.Arduino['inittm1637'] = function(block) {
var dropdown_PINS = this.getFieldValue('PINS');
var dropdown_PINSS = this.getFieldValue('PINSS');
Blockly.Arduino.definitions_['include_inittm1637'] = '#include <SevenSegmentTM1637.h>';
Blockly.Arduino.definitions_['inittm1637'] = 'SevenSegmentTM1637  display('+dropdown_PINS+','+dropdown_PINSS+');';
return  'display.begin();\n';
}
//TM1637数码管设置亮度
Blockly.Arduino['tm1637setlight'] = function(block) {
var value_tm1637setlights = Blockly.Arduino.valueToCode(this, 'tm1637setlights', Blockly.Arduino.ORDER_ATOMIC);
return  'display.setBacklight('+value_tm1637setlights+');\n';
}
//TM1637数码管显示
Blockly.Arduino['tm1637print'] = function(block) {
var value_tm1637prints = Blockly.Arduino.valueToCode(this, 'tm1637prints', Blockly.Arduino.ORDER_ATOMIC);
return  'display.print('+value_tm1637prints.replace(/'/g, '"')+');\n';
}
//TM1637数码管清屏
Blockly.Arduino['tm1637clear'] = function(block) {
return  'display.clear();\n';
}
//初始化步进电机
Blockly.Arduino['initstepper'] = function(block) {
var dropdown_PINS1 = this.getFieldValue('PINS1');
var dropdown_PINS2 = this.getFieldValue('PINS2');
var dropdown_PINS3 = this.getFieldValue('PINS3');
var dropdown_PINS4 = this.getFieldValue('PINS4');
var value_eachroundsteps = Blockly.Arduino.valueToCode(this, 'eachroundsteps', Blockly.Arduino.ORDER_ATOMIC);
var value_stepperspeed = Blockly.Arduino.valueToCode(this, 'stepperspeed', Blockly.Arduino.ORDER_ATOMIC);
Blockly.Arduino.definitions_['include_initstepper'] = '#include <Stepper.h>';
Blockly.Arduino.definitions_['initstepper'] = 'Stepper mystepper('+value_eachroundsteps+','+dropdown_PINS1+','+dropdown_PINS2+','+dropdown_PINS3+','+dropdown_PINS4+');';
return  'mystepper.setSpeed('+value_stepperspeed+');\n';
}
//步进电机移动步数
Blockly.Arduino['steppermove'] = function(block) {
var value_steppermoves = Blockly.Arduino.valueToCode(this, 'steppermoves', Blockly.Arduino.ORDER_ATOMIC);
return  'mystepper.step('+value_steppermoves+');\n';
}
//单电机
Blockly.Arduino['dcmotor'] = function(block) {
var dropdown_PINS1 = this.getFieldValue('PINS1');
var dropdown_PINS2 = this.getFieldValue('PINS2');
var value_dcmotors = Blockly.Arduino.valueToCode(this, 'dcmotors', Blockly.Arduino.ORDER_ATOMIC);
Blockly.Arduino.definitions_['dcmotors'] = ' void motorModule(int pinDir, int pinPwm, int speed){\n    pinMode(pinDir, OUTPUT);\n    if(speed>=0){\n        digitalWrite(pinDir, 1);\n    }else{\n        digitalWrite(pinDir, 0);\n    }\n    analogWrite(pinPwm, abs(speed));\n}';
return  'motorModule('+dropdown_PINS1+', '+dropdown_PINS2+', '+value_dcmotors+');\n';
}
//单电机驱动
Blockly.Arduino['dcmotor2'] = function(block) {
var dropdown_PINS1 = this.getFieldValue('PINS1');
var dropdown_PINS2 = this.getFieldValue('PINS2');
var dropdown_pwm = this.getFieldValue('pwm');
var value_dcmotors2 = Blockly.Arduino.valueToCode(this, 'dcmotors2', Blockly.Arduino.ORDER_ATOMIC);
Blockly.Arduino.definitions_['dcmotor2'] = ' void motorModule2(int IN1, int IN2, int pinPwm, int speed){\n    pinMode(IN1, OUTPUT);\n    pinMode(IN2, OUTPUT);\n    if(speed>=0){\n        digitalWrite(IN1, 1);\n        digitalWrite(IN2, 0);\n    }else{\n        digitalWrite(IN1, 0);\n        digitalWrite(IN2, 1);\n    }\n    analogWrite(pinPwm, abs(speed));\n}\n';
return  'motorModule2('+dropdown_PINS1+', '+dropdown_PINS2+','+dropdown_pwm+', '+value_dcmotors2+');\n';
}
//蜂鸣器初始化
Blockly.Arduino['buzzerinit'] = function(block) {
var dropdown_PINS1 = this.getFieldValue('buzzerinits');
return  'pinMode('+dropdown_PINS1+', OUTPUT);\n';
}
//蜂鸣器播放声音
Blockly.Arduino['buzzerplay'] = function(block) {
var dropdown_PINS1 = this.getFieldValue('buzzerinits');
var value_hz = Blockly.Arduino.valueToCode(this, 'hz', Blockly.Arduino.ORDER_ATOMIC);
var value_delays = Blockly.Arduino.valueToCode(this, 'delays', Blockly.Arduino.ORDER_ATOMIC);
return  'tone('+dropdown_PINS1+', '+value_hz+', '+value_delays+');\n';
}
//蜂鸣器播放声音选择声音
Blockly.Arduino['buzzerplay2'] = function(block) {
var dropdown_buzzerinitss = this.getFieldValue('buzzerinitss');
var dropdown_songs = this.getFieldValue('songs');
Blockly.Arduino.definitions_['include_buzzerplay2'] = '#include <Buzzer.h>\n#include <Sounds.h>';
Blockly.Arduino.definitions_['buzzerplay2'] = 'Buzzer mBuzzer = Buzzer('+dropdown_buzzerinitss+');';
if(dropdown_songs===("S_connection")){
	var code = 'mBuzzer._tone(note_E5, 50, 30);\nmBuzzer._tone(note_E6, 55, 25);\nmBuzzer._tone(note_A6, 60, 10);\n';
}
if(dropdown_songs===("S_disconnection")){
	var code = 'mBuzzer._tone(note_E5, 50, 30)\n;mBuzzer._tone(note_A6, 55, 25);\nmBuzzer._tone(note_E6, 50, 10);\n';
}
if(dropdown_songs===("S_buttonPushed")){
	var code = 'mBuzzer.bendTones (note_E6, note_G6, 1.03, 20, 2);\ndelay(30);\nmBuzzer.bendTones (note_E6, note_D7, 1.04, 10, 2);\n';
}
if(dropdown_songs===("S_mode3")){
	var code = 'mBuzzer._tone(note_E6, 50, 100);\nmBuzzer._tone(note_G6, 50, 80);\nmBuzzer._tone(note_D7, 300, 0);\n ';
}
if(dropdown_songs===("S_surprise")){
	var code = 'mBuzzer.bendTones(800, 2150, 1.02, 10, 1);\nmBuzzer.bendTones(2149, 800, 1.03, 7, 1);\n';
}
if(dropdown_songs===("S_OhOoh")){
	var code = 'for (int i = 880; i < 2000; i = i * 1.04) {\nmBuzzer._tone(note_B5, 5, 10);\n}\n';
}
if(dropdown_songs===("S_OhOoh2")){
	var code = 'for (int i = 1880; i < 3000; i = i * 1.03) {\nmBuzzer._tone(note_C6, 10, 10);\n}\n';
}
if(dropdown_songs===("S_cuddly")){
	var code = 'mBuzzer.bendTones(700, 900, 1.03, 16, 4);\nmBuzzer.bendTones(899, 650, 1.01, 18, 7);\n';
}
if(dropdown_songs===("S_happy")){
	var code = 'mBuzzer.bendTones(1500, 2500, 1.05, 20, 8);\nmBuzzer.bendTones(2499, 1500, 1.05, 25, 8);\n';
}
if(dropdown_songs===("S_sad1")){
	var code = 'mBuzzer.bendTones(1600, 3000, 1.02, 2, 15);\n';
}
if(dropdown_songs===("S_sad2")){
	var code = 'mBuzzer.bendTones(1600, 4000, 1.02, 2, 20);\nmBuzzer.bendTones(4000, 3000, 1.02, 2, 20);\n';
}
return code;
}
//红外遥控初始化
Blockly.Arduino['kw_initir'] = function () {
	 var value_initir = Blockly.Arduino.valueToCode(this, 'initir', Blockly.Arduino.ORDER_ATOMIC);
	Blockly.Arduino.definitions_['define_initir'] = '#include <IRremote.h>\n#include <keymap.h>\n'+'IRremote ir('+value_initir+');\n';
	var code = 'ir.begin();\n';
    return code;
};
//普通遥控器按下
Blockly.Arduino['kw_irKeyPress'] = function(block) {
//var dropdown_DS18B20ss = this.getFieldValue('DS18B20ss');
var dropdown_Irkey = this.getFieldValue('Irkey');
var code = 'ir.getIrKey(ir.getCode(),1) == '+dropdown_Irkey+'';
return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//emakefun遥控器按下
Blockly.Arduino['kw_irKeyPress2'] = function(block) {
//var dropdown_DS18B20ss = this.getFieldValue('DS18B20ss');
var dropdown_Irkey2 = this.getFieldValue('Irkey2');
var code = 'ir.getIrKey(ir.getCode(),2) == '+dropdown_Irkey2+'';
return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//初始化MAX7219点阵屏
Blockly.Arduino['initmax7219init'] = function(block) {
   var pin_PIN1 =  this.getFieldValue('PIN1');
   var pin_PIN2 =  this.getFieldValue('PIN2');
   var pin_PIN3 =  this.getFieldValue('PIN3');
var hDisplays = Blockly.Arduino.valueToCode(this, 'Horizontalcount', Blockly.Arduino.ORDER_ATOMIC);
//var vDisplays = Blockly.Arduino.valueToCode(this, 'verticalcount', Blockly.Arduino.ORDER_ATOMIC);
Blockly.Arduino.definitions_['include_SPI'] = '#include <MaxMatrix.h>';
Blockly.Arduino.definitions_['var_declare_Max72xxPanel'] = 'MaxMatrix ledmatrix('+pin_PIN1+','+pin_PIN2+','+pin_PIN3+', '+hDisplays+');';
var code = 'ledmatrix.init();\nledmatrix.setIntensity(1);\nledmatrix.clearMatrix();\n';
return code;
}
/*/点阵屏预设图案
Blockly.Arduino.Matrix_img = function() {
var dropdown_img_ = this.getFieldValue('img_');
var code = '"' + dropdown_img_ + '"';
code = '{';
for (var i = 0; i < 15; i += 2) {
  code += '0x' + dropdown_img_.substr(i, 2) + ((i != 14) ? ',' : '');
}
code += '};\n';
Blockly.Arduino.definitions_['matrix_img_' + dropdown_img_] = "byte " + 'matrix_img_' + dropdown_img_ + "[]=" + code;
return ['matrix_img_' + dropdown_img_, Blockly.Arduino.ORDER_ATOMIC];
};*/
//点阵屏显示
Blockly.Arduino.MAX7219_DisplayChar = function() {
var dropdown_draw =  this.getFieldValue('draw');
return 'ledmatrix.writeFull(ledmatrix.getMouthShape('+dropdown_draw+'));';
};
//点阵屏单点亮灭
Blockly.Arduino.max7219singlepoint = function() {
var dropdown_PIN =  this.getFieldValue('PIN');
var value_Xaxis = Blockly.Arduino.valueToCode(this, 'Xaxis', Blockly.Arduino.ORDER_ATOMIC);
var value_Yaxis = Blockly.Arduino.valueToCode(this, 'Yaxis', Blockly.Arduino.ORDER_ATOMIC);
return 'ledmatrix.setDot('+value_Xaxis+','+value_Yaxis+','+dropdown_PIN+');\n';
};
//初始化ds1302
Blockly.Arduino.initds1302 = function() {
var dropdown_RSTS =  this.getFieldValue('RSTS');
var dropdown_DATS =  this.getFieldValue('DATS');
var dropdown_CLKS =  this.getFieldValue('CLKS');
Blockly.Arduino.definitions_['include_initds1302'] = '#include <DS1302.h>';
Blockly.Arduino.definitions_['initds1302'] = 'DS1302 myRTC('+dropdown_RSTS+','+dropdown_DATS+','+dropdown_CLKS+');';
return '';
};
//获取ds1302年月日时分秒
Blockly.Arduino.getds1302date = function() {
var dropdown_DATES =  this.getFieldValue('DATES');
var code = 'myRTC.'+dropdown_DATES+'()';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
};
//ds1302设置时分秒
Blockly.Arduino.setds1302time = function() {
var value_hour = Blockly.Arduino.valueToCode(this, 'hour', Blockly.Arduino.ORDER_ATOMIC);
var value_minute = Blockly.Arduino.valueToCode(this, 'minute', Blockly.Arduino.ORDER_ATOMIC);
var value_second = Blockly.Arduino.valueToCode(this, 'second', Blockly.Arduino.ORDER_ATOMIC);
return 'myRTC.setTime('+ value_hour + ', ' + value_minute + ', ' + value_second + ');\n';
};
//ds设置年月日
Blockly.Arduino.setds1302date = function() {
var value_year = Blockly.Arduino.valueToCode(this, 'year', Blockly.Arduino.ORDER_ATOMIC);
var value_month = Blockly.Arduino.valueToCode(this, 'month', Blockly.Arduino.ORDER_ATOMIC);
var value_day = Blockly.Arduino.valueToCode(this, 'day', Blockly.Arduino.ORDER_ATOMIC);
return 'myRTC.setDate(' + value_day +', '+ value_month +', '+ value_year +');\n';
};
//初始化ds3231
Blockly.Arduino.initds3231 = function() {
Blockly.Arduino.definitions_['include_initds3231'] = '#include <DS3231.h>\n';
Blockly.Arduino.definitions_['initds3231'] = 'DS3231 Clock;\n';
return '';
};
//获取ds3231年月日时分秒
Blockly.Arduino.getds3231date = function() {
var dropdown_DATES2 =  this.getFieldValue('DATES2');
var code = 'Clock.'+dropdown_DATES2+'';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
};
//ds3231设置时分秒
Blockly.Arduino.setds3231time = function() {
var value_hour2 = Blockly.Arduino.valueToCode(this, 'hour2', Blockly.Arduino.ORDER_ATOMIC);
var value_minute2 = Blockly.Arduino.valueToCode(this, 'minute2', Blockly.Arduino.ORDER_ATOMIC);
var value_second2 = Blockly.Arduino.valueToCode(this, 'second2', Blockly.Arduino.ORDER_ATOMIC);
return 'Clock.setHour('+value_hour2+');\nClock.setMinute('+value_minute2+');\nClock.setSecond('+value_second2+');\n';
};
//ds3231设置年月日
Blockly.Arduino.setds3231date = function() {
var value_year2 = Blockly.Arduino.valueToCode(this, 'year2', Blockly.Arduino.ORDER_ATOMIC);
var value_month2 = Blockly.Arduino.valueToCode(this, 'month2', Blockly.Arduino.ORDER_ATOMIC);
var value_day2 = Blockly.Arduino.valueToCode(this, 'day2', Blockly.Arduino.ORDER_ATOMIC);
return 'Clock.setYear('+value_year2+');\nClock.setMonth('+value_month2+');\nClock.setDate('+value_day2+');\n';
};
//rgb初始化
Blockly.Arduino['rgbinit'] = function(block) {
var dropdown_rgbinits = this.getFieldValue('rgbinits');
var value_pixel = Blockly.Arduino.valueToCode(this, 'pixel', Blockly.Arduino.ORDER_ATOMIC);
Blockly.Arduino.definitions_['include_rgbinit'] = '#include <Adafruit_NeoPixel.h>';
Blockly.Arduino.definitions_['rgbinit'] = 'Adafruit_NeoPixel neopix_'+dropdown_rgbinits+'('+value_pixel+', '+dropdown_rgbinits+');';
return  'neopix_'+dropdown_rgbinits+'.begin();\n';
}
//rgb显示颜色
Blockly.Arduino['rgbdisplay'] = function(block) {
var dropdown_rgbinits = this.getFieldValue('rgbinits');
var value_pixel = Blockly.Arduino.valueToCode(this, 'pixel', Blockly.Arduino.ORDER_ATOMIC);
var value_rgbred = this.getFieldValue('rgbred');
var value_rgbgreen = this.getFieldValue('rgbgreen');
var value_rgbblue =  this.getFieldValue('rgbblue');
return  'neopix_'+dropdown_rgbinits+'.setPixelColor('+value_pixel+', '+value_rgbred+', '+value_rgbgreen+', '+value_rgbblue+');\n';
}
//lm35初始化
Blockly.Arduino['lm35init'] = function(block) {
var dropdown_lm35inits = this.getFieldValue('lm35inits');
return  'pinMode('+dropdown_lm35inits+', INPUT);\n';
}
//lm35获取温度
Blockly.Arduino['lm35gettemp'] = function(block) {
var dropdown_lm35initss = this.getFieldValue('lm35initss');
var code = 'analogRead('+dropdown_lm35initss+')*0.488';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//ds18b20初始化
Blockly.Arduino['ds18b20init'] = function(block) {
var dropdown_DS18B20s = this.getFieldValue('DS18B20s');
Blockly.Arduino.definitions_['include_ds18b20init'] = '#include <DallasTemperature.h>\n#include <OneWire.h>';
Blockly.Arduino.definitions_['ds18b20init'] = 'DeviceAddress insideThermometer;\nOneWire oneWire_'+dropdown_DS18B20s+'('+dropdown_DS18B20s+');\nDallasTemperature sensors_'+dropdown_DS18B20s+'(&oneWire_'+dropdown_DS18B20s+');';
Blockly.Arduino.definitions_['func_ds18b20init'] = ' float ds18b20_getTemp(int w) {\n   sensors_'+dropdown_DS18B20s+'.requestTemperatures();\n   if(w==0) {\n   return sensors_'+dropdown_DS18B20s+'.getTempC(insideThermometer);\n   }\n   else {\n   return sensors_'+dropdown_DS18B20s+'.getTempF(insideThermometer);\n   }\n   }';
return  'sensors_'+dropdown_DS18B20s+'.getAddress(insideThermometer, 0);\nsensors_'+dropdown_DS18B20s+'.setResolution(insideThermometer, 9);\n';
}
//ds18b20获取温度
Blockly.Arduino['ds18b20gettemp'] = function(block) {
//var dropdown_DS18B20ss = this.getFieldValue('DS18B20ss');
var dropdown_temps = this.getFieldValue('temps');
var code = 'ds18b20_getTemp('+dropdown_temps+')';
return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//mpu6050重力感应器初始化
Blockly.Arduino['weightinit'] = function(block) {
Blockly.Arduino.definitions_['include_weightinit'] = '#include <MPU6050.h>\n#include <Wire.h>';
Blockly.Arduino.definitions_['weightinit'] = 'MPU6050 mpu;';
return  'mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G);\n';
}
//weightfresh
Blockly.Arduino['weightfresh'] = function(block) {
return  'Vector normAccel = mpu.readNormalizeAccel();\nVector normGyro = mpu.readNormalizeGyro();\n';
}
//重力感应器mpu6050获取加速度
Blockly.Arduino['weightgeta'] = function(block) {
var dropdown_weightgetas = this.getFieldValue('weightgetas');
var code = 'normAccel.'+dropdown_weightgetas+'';
return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//重力感应器mpu6050获取角度
Blockly.Arduino['weightgetd'] = function(block) {
var dropdown_weightgetds = this.getFieldValue('weightgetds');
var code = 'normGyro.'+dropdown_weightgetds+'';
return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//rgb超声波模块初始化
Blockly.Arduino['initrgbultrasonic'] = function(block) {
var dropdown_ulPINS = this.getFieldValue('ulPINS');
var dropdown_rgbPINS = this.getFieldValue('rgbPINS');
Blockly.Arduino.definitions_['include_initrgbultrasonict'] = '#include <RgbUltrasonic.h>\n';
Blockly.Arduino.definitions_['initrgbultrasonic'] = 'RgbUltrasonic mRUS04('+dropdown_ulPINS+','+dropdown_rgbPINS+');\n';
return  '';
}
/*/rgb超声波模块设置颜色
Blockly.Arduino['rgbultrasonicsetcolor'] = function(block) {
var dropdown_rgbultrasonicposition = this.getFieldValue('rgbultrasonicposition');
var dropdown_rgbultrasoniccolor = this.getFieldValue('rgbultrasoniccolor');
return  'mRUS04.SetRgbColor('+dropdown_rgbultrasonicposition+', '+dropdown_rgbultrasoniccolor+');\n';
}*/
//rgb超声波模块设置颜色样式
Blockly.Arduino['rgbultrasonicsetcolorstyle'] = function(block) {
var dropdown_rgbultrasonicposition = this.getFieldValue('rgbultrasonicposition');
var dropdown_rgbultrasoniccolor = this.getFieldValue('rgbultrasoniccolor');
var dropdown_rgbultrasoniccolorstyle = this.getFieldValue('rgbultrasoniccolorstyle');
return  'mRUS04.SetRgbEffect('+dropdown_rgbultrasonicposition+', '+dropdown_rgbultrasoniccolor+', '+dropdown_rgbultrasoniccolorstyle+');\n';
}
/*设置RGB超声波模块呼吸显示
Blockly.Arduino['rgbultrasonicsetbreathe'] = function(block) {
var dropdown_rgbultrasonicposition = this.getFieldValue('rgbultrasonicposition');
return  'mRUS04.SetRgbEffect('+dropdown_rgbultrasonicposition+', RGB_WHITE, E_EFFECT_BREATHING);\n';
}*/
//RGB超声波模块读取超声波距离
Blockly.Arduino['rgbultrasonicreaddistance'] = function(block) {
var code = 'mRUS04.GetUltrasonicDistance()';
return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//七彩led初始化
Blockly.Arduino['_7led'] = function(block) {
var dropdown_PINS = this.getFieldValue('PINS');
return  'pinMode(' + dropdown_PINS + ', OUTPUT); \n';
}
//七彩led亮灭
Blockly.Arduino['_7ledon'] = function(block) {
var dropdown_PINS = this.getFieldValue('PINS');
var dropdown_STATE = this.getFieldValue('STATE');
return  'digitalWrite(' + dropdown_PINS + ', '+dropdown_STATE+'); \n';
}
//7段数码管初始化
Blockly.Arduino['_7duanshumaguaninit'] = function(block) {
var dropdown_PINA = this.getFieldValue('PINA');
var dropdown_PINB = this.getFieldValue('PINB');
var dropdown_PINC = this.getFieldValue('PINC');
var dropdown_PIND = this.getFieldValue('PIND');
var dropdown_PINE = this.getFieldValue('PINE');
var dropdown_PINF = this.getFieldValue('PINF');
var dropdown_PING = this.getFieldValue('PING');
var dropdown_PINH = this.getFieldValue('PINH');
Blockly.Arduino.definitions_['include_7duanshumaguaninit'] = '#include<SegmentDisplay.h>';
Blockly.Arduino.definitions_['define_7duanshumaguaninit'] = 'SegmentDisplay _7SegmentDisplay('+dropdown_PINA+', '+dropdown_PINB+', '+dropdown_PINC+', '+dropdown_PIND+', '+dropdown_PINE+', '+dropdown_PINF+', '+dropdown_PING+', '+dropdown_PINH+');'
return  '';
}
//7段数码管显示数字
Blockly.Arduino['_7duanshumaguandisplay'] = function(block) {
var value__7duanshumaguandisplays = Blockly.Arduino.valueToCode(this, '_7duanshumaguandisplays', Blockly.Arduino.ORDER_ATOMIC);
return  '_7SegmentDisplay.DisplayChar((byte)'+value__7duanshumaguandisplays+'); \n';
}
//4位7段数码管初始化
Blockly.Arduino['_4x7duanshumaguaninit'] = function(block) {
var dropdown_PINA = this.getFieldValue('PINA');
var dropdown_PINB = this.getFieldValue('PINB');
var dropdown_PINC = this.getFieldValue('PINC');
var dropdown_PIND = this.getFieldValue('PIND');
var dropdown_PINE = this.getFieldValue('PINE');
var dropdown_PINF = this.getFieldValue('PINF');
var dropdown_PING = this.getFieldValue('PING');
var dropdown_PINH = this.getFieldValue('PINH');
var dropdown_PIND1 = this.getFieldValue('PIND1');
var dropdown_PIND2 = this.getFieldValue('PIND2');
var dropdown_PIND3 = this.getFieldValue('PIND3');
var dropdown_PIND4 = this.getFieldValue('PIND4');
Blockly.Arduino.definitions_['include__4x7duanshumaguaninit'] = '#include<SegmentDisplay.h>';
Blockly.Arduino.definitions_['define__4x7duanshumaguaninit'] = 'SegmentDisplay _4Bit_7SegmentDisplay('+dropdown_PINA+', '+dropdown_PINB+', '+dropdown_PINC+', '+dropdown_PIND+', '+dropdown_PINE+', '+dropdown_PINF+', '+dropdown_PING+', '+dropdown_PINH+', '+dropdown_PIND1+', '+dropdown_PIND2+', '+dropdown_PIND3+', '+dropdown_PIND4+');'
return  '';
}
//4位7段数码管显示数字
Blockly.Arduino['_4x7duanshumaguandisplay'] = function(block) {
var value__4x7duanshumaguandisplays = Blockly.Arduino.valueToCode(this, '_4x7duanshumaguandisplays', Blockly.Arduino.ORDER_ATOMIC);
return  '_4Bit_7SegmentDisplay.DisplayChar('+value__4x7duanshumaguandisplays+'); \n';
}
//矩阵键盘初始化
Blockly.Arduino['sqaurekeyinit'] = function(block) {
var dropdown_row1 = this.getFieldValue('row1');
var dropdown_row2 = this.getFieldValue('row2');
var dropdown_row3 = this.getFieldValue('row3');
var dropdown_row4 = this.getFieldValue('row4');
var dropdown_col1 = this.getFieldValue('col1');
var dropdown_col2 = this.getFieldValue('col2');
var dropdown_col3 = this.getFieldValue('col3');
var dropdown_col4 = this.getFieldValue('col4');
Blockly.Arduino.definitions_['include_sqaurekeyinit'] = '#include<Keypad.h>';
Blockly.Arduino.definitions_['define_sqaurekeyinit'] = 'const byte ROWS = 4;\nconst byte COLS = 4;\nchar hexaKeys[ROWS][COLS] = {\n{\'1\',\'2\',\'3\',\'A\'},\n{\'4\',\'5\',\'6\',\'B\'},\n{\'7\',\'8\',\'9\',\'C\'},\n{\'*\',\'0\',\'#\',\'D\'}\n};\nbyte rowPins[ROWS] = {'+dropdown_row1+', '+dropdown_row2+', '+dropdown_row3+', '+dropdown_row4+'};\nbyte colPins[COLS] = {'+dropdown_col1+', '+dropdown_col2+', '+dropdown_col3+', '+dropdown_col4+'};\nKeypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);\n'
return  'int i ;\n for(i=0 ; i< ROWS ; i++)    {\npinMode(rowPins[i],OUTPUT);\npinMode(colPins[i],OUTPUT);\n}\n';
}
//矩阵键盘获取的值
Blockly.Arduino.sqaurekeygetkey = function() {
var code = 'customKeypad.getKey()';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
};
//矩阵键盘是否获取到值
Blockly.Arduino.sqaurekeyisgetkey = function() {
var code = 'customKey';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
};
//rfid初始化
Blockly.Arduino['8x8ledinit'] = function(block) {
var dropdown_sdaPINS = this.getFieldValue('sdaPINS');
var dropdown_sckPINS = this.getFieldValue('sckPINS');
var dropdown_mosiPINS = this.getFieldValue('mosiPINS');
var dropdown_misoPINS = this.getFieldValue('misoPINS');
Blockly.Arduino.definitions_['include_rfidinit'] = '#include<RFID.h>\n#include<SPI.h>';
Blockly.Arduino.definitions_['define_rfidinit'] = 'RFID rfid(10,5);\nunsigned char RC_size;\nunsigned char blockAddr;\nunsigned char i,tmp;\nunsigned char status;\nunsigned char str[MAX_LEN];\nunsigned char sectorNewKeyA[16][16] = {\n{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},\n{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},\n{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},};\nunsigned char serNum[5];\nunsigned char sectorKeyA[16][16] = {\n{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},\n{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},\n{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},};\n';
return  'SPI.begin();\nrfid.init();\n';
}

//rfid是否侦测到信号？
Blockly.Arduino.rfidiscard = function() {
var code = 'rfid.isCard()';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
};
//rfid所读卡的卡号
Blockly.Arduino.rfidreadcard = function() {
Blockly.Arduino.definitions_['define_rfidreadcard'] = 'String RFID_readcardnum() {\nrfid.readCardSerial();\nString stringserNum=String(rfid.serNum[0], HEX)+String(rfid.serNum[1], HEX)+String(rfid.serNum[2], HEX)+String(rfid.serNum[3], HEX)+String(rfid.serNum[4], HEX);\nrfid.selectTag(rfid.serNum);\nreturn stringserNum;}\n'
var code = 'RFID_readcardnum()';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
};
//8x8ledinit 8x8点阵屏初始化
Blockly.Arduino['x8ledinit'] = function(block) {
var dropdown_ROW_0s = this.getFieldValue('ROW_0s');
var dropdown_ROW_1s = this.getFieldValue('ROW_1s');
var dropdown_ROW_2s = this.getFieldValue('ROW_2s');
var dropdown_ROW_3s = this.getFieldValue('ROW_3s');
var dropdown_ROW_4s = this.getFieldValue('ROW_4s');
var dropdown_ROW_5s = this.getFieldValue('ROW_5s');
var dropdown_ROW_6s = this.getFieldValue('ROW_6s');
var dropdown_ROW_7s = this.getFieldValue('ROW_7s');
var dropdown_LED_A1 = this.getFieldValue('LED_A1');
var dropdown_LED_B1 = this.getFieldValue('LED_B1');
var dropdown_LED_C1 = this.getFieldValue('LED_C1');
var dropdown_LED_D1 = this.getFieldValue('LED_D1');
var dropdown_LED_E1 = this.getFieldValue('LED_E1');
var dropdown_LED_F1 = this.getFieldValue('LED_F1');
var dropdown_LED_G1 = this.getFieldValue('LED_G1');
var dropdown_LED_H1 = this.getFieldValue('LED_H1');
Blockly.Arduino.definitions_['include_8x8ledinit'] = '#include<MaxMatrix.h>\n';
Blockly.Arduino.definitions_['define_8x8ledinit'] = 'MaxMatrix *m8x8Dot;\nconst byte ROW_PIN[8] = {'+dropdown_ROW_0s+', '+dropdown_ROW_1s+', '+dropdown_ROW_2s+', '+dropdown_ROW_3s+', '+dropdown_ROW_4s+', '+dropdown_ROW_5s+', '+dropdown_ROW_6s+', '+dropdown_ROW_7s+'};\nconst byte COL_PIN[8] = {'+dropdown_LED_A1+', '+dropdown_LED_B1+', '+dropdown_LED_C1+', '+dropdown_LED_D1+', '+dropdown_LED_E1+', '+dropdown_LED_F1+', '+dropdown_LED_G1+', '+dropdown_LED_H1+'};\n';
return  'm8x8Dot = new MaxMatrix_8x8(ROW_PIN, COL_PIN);\n';
}
//8x8点阵屏显示
Blockly.Arduino.x8leddisplay = function() {
var dropdown_draws =  this.getFieldValue('draws');
return 'm8x8Dot->writeFull(m8x8Dot->getMouthShape('+dropdown_draws+'));\n';
};
//不断扫描显示
Blockly.Arduino.x8ledloopscan = function() {
return 'm8x8Dot->scan();\n';
};
//74h初始化 74hinit
Blockly.Arduino._74hinit = function() {
var dropdown_BIT_CHOICE_11 =  this.getFieldValue('BIT_CHOICE_11');
var dropdown_BIT_CHOICE_22 =  this.getFieldValue('BIT_CHOICE_22');
var dropdown_BIT_CHOICE_33 =  this.getFieldValue('BIT_CHOICE_33');
var dropdown_BIT_CHOICE_44 =  this.getFieldValue('BIT_CHOICE_44');
var dropdown_STCP_PIN1 =  this.getFieldValue('STCP_PIN1');
var dropdown_SHCP_PIN1 =  this.getFieldValue('SHCP_PIN1');
var dropdown_DATA_PIN1 =  this.getFieldValue('DATA_PIN1');
Blockly.Arduino.definitions_['include__74hinit'] = '#include<SegmentDisplay.h>\n';
Blockly.Arduino.definitions_['define__74hinit'] = 'SegmentDisplay _74HC595_7SegmentDisplay('+dropdown_BIT_CHOICE_11+', '+dropdown_BIT_CHOICE_22+', '+dropdown_BIT_CHOICE_33+', '+dropdown_BIT_CHOICE_44+', '+dropdown_STCP_PIN1+', '+dropdown_SHCP_PIN1+', '+dropdown_DATA_PIN1+');';
return '';
};
//74h数码管显示 _74hinitisplay
Blockly.Arduino['_74hinitisplay'] = function(block) {
var value__74hinitisplays = Blockly.Arduino.valueToCode(this, '_74hinitisplays', Blockly.Arduino.ORDER_ATOMIC);
return  '_74HC595_7SegmentDisplay.DisplayChar((int)'+value__74hinitisplays+'); \n';
}
//74h熄灭 _74hoff
Blockly.Arduino['_74hoff'] = function(block) {
return  '_74HC595_7SegmentDisplay.TurnOffAllLed();\n';
}
//获取系统时间 getnowtime
Blockly.Arduino.getnowtime = function() {
var code = 'millis()';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
};
//hx711init
Blockly.Arduino['hx711init'] = function(block) {
  Blockly.Arduino.definitions_['include_hx711init'] = '#include<HX711.h>\n';
return  'Init_Hx711();\nGet_Maopi();\n';
}
//hx711getweight
Blockly.Arduino.hx711getweight = function() {
var code = 'Get_Weight()';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
};

//RGB(144,72,154)
String.prototype.colorRgb = function(){
  var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
	var sColor = this.toLowerCase();
	if(sColor && reg.test(sColor)){
		if(sColor.length === 4){
			var sColorNew = "#";
			for(var i=1; i<4; i+=1){
				sColorNew += sColor.slice(i,i+1).concat(sColor.slice(i,i+1));	
			}
			sColor = sColorNew;
		}
		//处理六位的颜色值
		var sColorChange = [];
		for(var i=1; i<7; i+=2){
			sColorChange.push(parseInt("0x"+sColor.slice(i,i+2)));	
		}
		return  sColorChange.join(",") ;
	}else{
		return sColor;	
	}
};







//字符串转int
Blockly.Arduino.stringtoint = function() {
  var value_stringtoints = Blockly.Arduino.valueToCode(this, 'stringtoints', Blockly.Arduino.ORDER_ATOMIC);
var code = ''+value_stringtoints+'.toInt()';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
};
//串口读取整数小数
Blockly.Arduino['serialreadint'] = function(block) {
		var dropdown_Serials9 = this.getFieldValue('Serials9');
    var dropdown_intfloat = this.getFieldValue('intfloat');
 var code = ''+dropdown_Serials9+'.'+dropdown_intfloat+'';
 return [code, Blockly.Arduino.ORDER_ATOMIC];
}
//sensing_touchingcolor11  #0e0c06
//串口读取整数小数
Blockly.Arduino['sensing_touchingcolor11'] = function(block) {
  // console.log("sensing_touchingcolor11:", this.colour_);
  // console.log("sensing_touchingcolor11====:", );
  var dropdown_Serials9 = block.childBlocks_[0].colour_; 
  var result = dropdown_Serials9.colorRgb();
  // console.log("sensing_touchingcolor11 result====:", result);
  // var dropdown_intfloat = this.getFieldValue('intfloat');
// var code = ''+dropdown_Serials9+'.'+dropdown_intfloat+'';
return [dropdown_Serials9, Blockly.Arduino.ORDER_ATOMIC];
}

    return Blockly;
}

module.exports = addArduinoCod ;
